#!/bin/bash
# podspec文件 转 podspec.json文件 的脚本工具类

# 获取spec版本号
ct_getSpecFileVersion() {
	fileName=$1
	
	cat ${fileName} | while read line
	do
		array=(${line//=/ })
		
		if [[ ${#array[@]} == 2 ]]; then
			if [[ ${array[0]} == *".version" ]];  then
				echo ${array[1]} |sed "s/[\"\']//g" # 去除两端的双引号
				break;
			fi
		fi
	done
}

# 遍历podsepc文件
for pod in `ls *.podspec`
do
	spec_name=${pod%.*} # 去掉后缀
	spec_ver=$(ct_getSpecFileVersion ${pod})
	if [[ ${#spec_ver} > 0 ]]; then
		fold="Specs/${spec_name}/${spec_ver}"
	fi
	
	mkdir -p $fold
	pod ipc spec $pod >> "${fold}/${pod}.json"

	echo "'${spec_name}' completed."
done
